home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_055 / csh / shell.doc < prev    next >
Text File  |  1992-05-06  |  21KB  |  697 lines

  1.         INSTRUCTIONS FOR SHELL V2.05M    20-Jan-87
  2.         -----------------------------
  3.  
  4. SHELL V2.04. (C)Copyright 1986, Matthew Dillon, All Rights Reserved.
  5. You may distribute this program for non-profit only.
  6.  
  7.         Shell V2.05M by Steve Drew.
  8.         --------------------------
  9. --------------------------------------------------------------------------
  10. Note:
  11.     These Instructions are my specific 2.05M Instructions and Matt's 2.04
  12.     merged together. 
  13.     A preceding | indicates that funtionality has been changed/enhanced,
  14.     a preceding * indicates that this is functionality or a command
  15.     that has been added in my manx version.
  16.  
  17.     for version releases see readme file. 
  18. ---------------------------------------------------------------------------
  19.  
  20.       (A)   Compiling
  21.       (B)   Overview
  22.       (C)   Quicky tech notes on implimentation.
  23.  
  24.       (D)   Command pre-processor
  25.       (E)   Command Line Editing
  26.       (F)   Function Keys
  27.       (G)   Command-list
  28.       (H)   special SET variables
  29.  
  30.       (I)   example .login file.
  31.  
  32.  
  33.  
  34. (A) COMPILING:
  35.  
  36. |   makefile supplied.
  37. |
  38. |   Your manx should be patched for 1.2 (c.lib) otherwise fexec wont work
  39. |   and you'll just get "command not found" for all external commands.
  40.  
  41.  
  42. (B) OVERVIEW:
  43.  
  44.    OVERVIEW of the major features:
  45.  
  46.    -simple history
  47.    -redirection
  48.    -piping
  49.    -command search path 
  50.    -aliases
  51.    -variables & variable handling (embedded variables)
  52.    -file name expansion via '?' and '*'
  53.    -conditionals
  54.    -source files  (w/ gotos and labels)
  55.    -many built in commands to speed things up
  56.  
  57.    PROBLEMS
  58.  
  59.    -Not really a bug  but, if you want to pass a quote to an
  60.     external command dont forget to use the overide '\' character
  61.     eg.   Relabel df0: \"Blank disk\"
  62.  
  63.    -Append '>>' does NOT work with BCPL programs.  It does work with all
  64.     internal and non-bcpl programs.
  65.  
  66.    -This version runs UNDER WORKBENCH 1.2 ONLY.
  67.     
  68.  
  69. (C) QUICK TECH NOTES:
  70.  
  71.    PIPES have been implimented using temporary RAM: files.  Thus, you
  72.    should be careful when specifying a 'ram:*' expansion as it might
  73.    include the temp. files.  These files are deleted on completion of
  74.    the pipe segment.
  75.  
  76.    The file names used are completely unique, even with multiple shell
  77.    running simultaniously.
  78.  
  79.    My favorite new feature is the fact that you can now redirect to and
  80.    from, and pipe internal commands.  'echo charlie >ram:x', for
  81.    instance.  Another favorite:
  82.  
  83.       echo "echo mem | shell" | shell
  84.  
  85.    To accomplish these new features, I completely re-wrote the command
  86.    parser in execom.c
  87.  
  88.    The BCPL 'RUN' command should not be redirected.. .strange things
  89.    happen.
  90.  
  91.    NO BCPL program should be output-append redirected (>>).
  92.  
  93.  
  94. (D)   Command pre-processor
  95.  
  96.    preprocessing is done on the command line before it is passed on to
  97.    an internal or external routine:
  98.  
  99.    ^c       where c is a character is converted to that control character.
  100.             Thus, say '^l' for control-l.
  101.  
  102.    $name    where name is a variable name.  Variable names can consist of
  103.             0-9, a-z, A-Z, and underscore (_).  The contents of the
  104.             specified variable is used.  If the variable doesn't exist,
  105.             the specifier is used.  That is, if the variable 'i' contains
  106.             'charlie', then '$i' -> 'charlie'.  If the variable 'i' doesn't
  107.             exist, then '$i'->'$i' .
  108.  
  109.    ;        delimits commands.   echo charlie ; echo ben.
  110.  
  111.    ' '      (a space). Spaces delimit arguments.
  112.  
  113.    "string" a quoted string.  For instance, if you want to echo five spaces
  114.             and an 'a':
  115.  
  116.             echo      a       -> a
  117.             echo "    a"      ->      a
  118.  
  119.    \c       overide the meaning of special characters.  '\^a' is a
  120.             circumflex and an a rather than control-a.  To get a backslash,
  121.             you must say '\\'.
  122.  
  123.             also used to overide alias searching for commands.
  124.  
  125.    >file    specify output redirection.  All output from the command is
  126.             placed in the specified file.
  127.  
  128.    >>file   specify append redirection (Does not work with BCPL programs).
  129.  
  130.    <file    specify input redirection.  The command takes input from the
  131.             file rather than the keyboard (note: not all commands require
  132.             input).  It makes no sense to say  'echo <charlie' since
  133.             the 'echo' command only outputs its arguments.
  134.  
  135.    |        PIPE specifier.  The output from the command on the left becomes
  136.             the input to the command on the right.  The current SHELL
  137.             implimentation uses temporary files to store the data.
  138.  
  139.    !!       execute the previously executed command.
  140.    !nn      (nn is a number).  Insert the history command numbered n (see
  141.             the HISTORY command)
  142.    !partial search backwards through the history list for a command which
  143.             looks the same as 'partial', and execute it.
  144.  
  145.    #        Enter comment.  The rest of the line is discarded (note: \#
  146.             will, of course, overide the comment character's special
  147.             meaning)
  148.  
  149.  
  150. (E) Command Line Editing
  151.  
  152. *  - Command line can be upto 255 chars.
  153. *  - Inserts and deletes are handled correctly over
  154. *    multiple screen lines. The program will keep track of
  155. *    the line width should the window get resized.
  156. *
  157. *    KEY DEFINITIONS:
  158. *             Up Arrow    Recal previous commands
  159. *          Down Arrow  Recal commands
  160. *        Left Arrow  Move cursor about command line.
  161. *        Right Arrow  "     "      "      "      "
  162. *        ^A        Toggle insert/overtype mode.
  163. *        ^D        EOF
  164. *        ^E        Put cursor at end of text.
  165. *        ^K        Delete to end of line.
  166. *        ^R        Retype current line.
  167. *        ^U        Erase entire line.
  168. *        ^X        Erase entire line.
  169. *        ^Z        Put cursor at start of text.
  170. *        f1 - f10    Execute command if variable exists.
  171. *        F1 - F10    More commands (Shifted f keys).
  172. *        Help         invokes help command
  173.  
  174. (F) Function keys.
  175.         
  176. *  - Just set the variable f1-f10 or F1-F10 (shifted) to
  177. *    the desired string.
  178. *
  179. *      eg. 
  180. *           $ set f1 "dir -s df0:"            
  181.  
  182.  
  183. (G)  COMMAND LIST:
  184.  
  185.    The first argument is the command-name... if it doesn't exist in the
  186.    list below and isn't an alias, it is assumed to be an external (disk)
  187.    command.
  188.  
  189.    AUTOMATIC SOURCING may be accomplished by naming shell scripts with a
  190.    .sh suffix.  Thus, if you say 'stuff' and the file 'stuff.sh' exists in
  191.    your current or C: directory, it will be SOURCED with any arguments you
  192.    have placed in the $_passed variable.
  193.  
  194.    EXCEPTION_PROCESSING:
  195.  
  196.       if no _except variable exists, any command which fails causes the
  197.       rest of the line to abort as if an ABORTLINE had been executed.  If
  198.       the _except variable exists, it is of the form:
  199.  
  200.       "nnn;commands..."
  201.  
  202.       where nnn is some value representing the minimum return code required
  203.       to cause an error.  Whenever a command returns a code which is
  204.       larger or equal to nnn, the commands in _except are executed before
  205.       anything.  WHEN _except EXISTS, THE COMMAND LINE DOES NOT ABORT
  206.       AUTOMATICALLY.  Thus, if you want the current line being executed
  207.       to be aborted, the last command in _except should be an "abortline".
  208.  
  209.       exception handling is disabled while in the exception handling routine
  210.       (thus you can't get into any infinite loops this way).
  211.  
  212.       Thus if _except = ";", return codes are completely ignored.
  213.  
  214.       example:
  215.  
  216.       set _except "20;abortline"
  217.  
  218.  
  219.    ABORTLINE
  220.  
  221.       or just 'abort'.  Causes the rest of the line to be aborted. Used in
  222.       conjunction with exception handling.
  223.  
  224.       % echo a;abort;echo b
  225.       a
  226.  
  227.  
  228.    HELP
  229.  
  230. |     simply displays all the available commands.  The commands are
  231. |     displayed in search-order.  That is, if you give a partial name
  232. |     the first command that matches that name in this list is the one
  233. |     executed.  Generally, you should specify enough of a command so that
  234. |     it is completely unique.
  235.  
  236.    QUIT
  237.    EXIT
  238.    RETURN [n]
  239.  
  240.       quit my SHELL (awww!).  End, El-Zappo, Kapow. Done, Finis.  If you
  241.       use RETURN and are on the top source level, the shell exits with the
  242.       optional return code.  (see RETURN below)
  243.  
  244.  
  245.    SET
  246.    SET name
  247.    SET name string
  248.  
  249.       The first method lists all current variable settings.
  250.       The second method lists the setting for that particular variable,
  251.       or creates the variable if it doesn't exist (to "")
  252.       The last method sets a variable to a string.
  253.  
  254.       see the section on special _ variables down below
  255.  
  256.  
  257.    UNSET name name name....
  258.  
  259.       unset one or more variables.  Deletes them entirely.
  260.  
  261.  
  262.    ALIAS
  263.    ALIAS name
  264.    ALIAS name string
  265.  
  266.       same as SET, but applies to the alias list.  You can alias a single
  267.       name to a set of commands.  For instance:
  268.  
  269.       alias hi "echo a; echo b"
  270.  
  271.       then you can simply say 'hi'.  Aliases come in two forms the second
  272.       form allows you to place the arguments after an alias in a variable
  273.       for retrieval:
  274.  
  275.       alias xxx "%i echo this $i is a test"
  276.  
  277.       % xxx charlie
  278.       this charlie is a test
  279.  
  280.       The rest of the command line is placed in the specified variable
  281.       for the duration of the alias.  This is especially useful when used
  282.       in conjunction with the 'FOREACH' command.
  283.  
  284.  
  285.    UNALIAS name name name...
  286.  
  287.       delete aliases..
  288.  
  289.  
  290.    ECHO string
  291.    ECHO -n string
  292.  
  293.       echo the string to the screen.  If '-n' is specified, no newline is
  294.       output.
  295.  
  296.  
  297.    STRHEAD  varname breakchar string
  298.  
  299.       remove everything after and including the breakchar in 'string' and
  300.       place in variable 'varname':
  301.  
  302.          % strhead j . aaa.bbb
  303.          % echo $j
  304.          aaa
  305.          %
  306.  
  307.  
  308.    STRTAIL  varname breakchar string
  309.  
  310.       remove everything before and including the breakchar in 'string' and
  311.       place in variable 'varname':
  312.  
  313.          % strtail j . aaa.bbb
  314.          % echo $j
  315.          bbb
  316.          %
  317.  
  318.  
  319.    SOURCE file [arguments]
  320.  
  321.       execute commands from a file.  You can create SHELL programs in
  322.       a file and then execute them with this command.  Source'd files
  323.       have the added advantage that you can have loops in your command
  324.       files (see GOTO and LABEL).  You can pass SOURCE files arguments
  325.       by specifying arguments after the file name.  Arguments are passed
  326.       via the _passed variable (as a single string).
  327.  
  328.       Automatic 'sourcing' is accomplished by placing a .sh extension on
  329.       the file and executing it as you would a C program:
  330.  
  331.       --------- file hello.sh ---------
  332.       foreach i ( $_passed ) "echo yo $i"
  333.       ---------------------------------
  334.       % hello a b c
  335.       yo a
  336.       yo b
  337.       yo c
  338.  
  339.  
  340.    MV from to
  341.    MV from from from ... from todir
  342.  
  343.       Allows you to rename a file or move it around within a disk.  Allows
  344.       you to move 1 or more files into a single directory.
  345.  
  346.  
  347.    CD
  348.    CD ..
  349.    CD path
  350.  
  351. |     Change your current working directory.  You may specify '..' to go
  352. |     back one directory (this is a CD specific feature, and does not
  353. |     work with normal path specifications).
  354.  
  355.       CD without any arguments displays the path of the directory you
  356.       are currently in.
  357.  
  358.  
  359.    PWD
  360.       rebuild _cwd by backtracing from your current directory.
  361.  
  362.  
  363.    RM [-r] file file file...
  364.  
  365.       DeleteFile().  Remove the specified files.  Remove always returns
  366.       errorcode 0.  You can remove empty directories.  The '-r' option
  367.       will remove non-empty directories by recursively removing all sub
  368.       directories.
  369. *     If  you specify any wildcard deletes the files will be listed as
  370. *     they are deleted. This can be suppressed by redirecting to nil: 
  371.  
  372.  
  373. |  COPY file file
  374. |  COPY file1 file2...fileN dir
  375. |  COPY [-r] dir1 dir2...dirN dir
  376.  
  377.       copy files or directories.  when copying directories, the "-r" option
  378.       must be specified to copy subdirectories as well.  Otherwise, only
  379.       top level files in the source directory are copied.
  380.  
  381. *     All files will be displayed as they are copied and directory's displayed
  382. *     as they are created. This output can be suppessed by redirecting to nil:
  383. *    eg. copy -r >nil: df0: df1:
  384. *     copy will abort after current file on Control-C.
  385.  
  386.    MKDIR name name name...
  387.  
  388.       create the following directories.
  389.  
  390.  
  391.    HISTORY [partial_string]
  392.  
  393.       Displays the enumerated history list.  The size of the list is
  394.       controlled by the _history variable.  If you specify a partial-
  395.       string, only those entries matching that string are displayed.
  396.  
  397.  
  398.    MEM
  399.  
  400.       Display current memory statistics for CHIP and FAST.
  401.  
  402.  
  403.    CAT [file file....]
  404.  
  405.       Type the specified files onto the screen.  If no file is specified,
  406.       STDIN in used.  CAT is meant to output text files only.
  407.  
  408.  
  409. |  DIR [-sdf] [path path ... ]
  410.  
  411. |    - default output show's date, protection, block size, byte size.
  412. *    - Dir command rewritten to allow options:
  413. *        -s short mutil(4) collum display of files
  414. *            (directory files are in italics).
  415. *        -d directorys only
  416. *        -f files only
  417. *        -e exclude files. Specify as the next argument a pattern
  418. *           for the files to be excluded. Do not use * or ? chars
  419. *           as the '*' is already appended to either side of the 
  420. *           pattern and this prevents the preprosesor from expanding
  421. *               them. eg. -e .c is merge to *.c* so any file spec 
  422. *           containing a ".c" string is skipped.               
  423. *
  424. *      eg. dir -se .info       (short directory exclude all .info files.)
  425.                 
  426. |      the directory command will also not expand files that are
  427. |      directories if as result of a wildcard expansion. eg:
  428. |      'dir df0:*'  and 'dir df0:' will give same results
  429. |      expect previously if df0:* was specified all subdirectories
  430. |      of df0: were expanded also.
  431. |      (to list the subdirectories: 'dir df0:*/*')
  432.                 
  433.  
  434.    DEVINFO [device: device:... ]
  435.  
  436.       Display Device statistics for the current device (CD base), or
  437.       specified devices.
  438. |     Gives block used/free, % used, errs and volume name.
  439.  
  440.  
  441.    FOREACH varname ( strings ) command
  442.  
  443.       'strings' is broken up into arguments.  Each argument is placed in
  444.       the variable 'varname' in turn and 'command' executed.  To execute
  445.       multiple commands, place them in quotes:
  446.  
  447.       % foreach i ( a b c d ) "echo -n $i;echo \" ha\""
  448.       a ha
  449.       b ha
  450.       c ha
  451.       d ha
  452.  
  453.       Foreach is especially useful when interpreting passed arguments in
  454.       an alias or source file.
  455.  
  456.       NOTE: a GOTO inside will have indeterminate results.
  457.  
  458.  
  459.    FOREVER command
  460.    FOREVER "command;command;command..."
  461.  
  462.       The specified commands are executed over and over again forever.
  463.  
  464.       -Execution stops if you hit ^C
  465.       -If the commands return with an error code.
  466.  
  467.       NOTE: a GOTO inside will have indeterminate results.
  468.  
  469.  
  470.    RETURN [value]
  471.  
  472.       return from a source file.  The rest of the source file is
  473.       discarded.  If given, the value becomes the return value for the
  474.       SOURCE command.  If you are on the top level, this value is returned
  475.       as the exit code for the shell.
  476.  
  477.  
  478.    IF argument conditional argument ;
  479.    IF argument
  480.  
  481.       If a single argument is something to another argument.  Conditional
  482.       clauses allowed:
  483.  
  484.       <, >, =, and combinations (wire or).  Thus <> is not-equal, >=
  485.       larger or equal, etc...
  486.  
  487.       If the left argument is numeric, both arguments are treated as
  488.       numeric.
  489.  
  490.       usually the argument is either a constant or a variable ($varname).
  491.  
  492.       The second form if IF is conditional on the existance of the argument.
  493.       If the argument is a "" string, then false , else TRUE.
  494.  
  495.  
  496.    ELSE ;
  497.  
  498.       else clause.
  499.  
  500.  
  501.    ENDIF ;
  502.  
  503.       the end of an if statement.
  504.  
  505.  
  506.    LABEL name
  507.  
  508.       create a program label right here.
  509.  
  510.  
  511.    GOTO label
  512.  
  513.       goto the specified label name.  You can only use this command from a
  514.       source file.
  515.  
  516.  
  517.    DEC var
  518.    INC var
  519.  
  520.       decrement or increment the numerical equivalent of the variable and
  521.       place the ascii-string result back into that variable.
  522.  
  523.  
  524.    INPUT varname
  525.  
  526.       input from STDIN (or a redirection, or a pipe) to a variable.  The
  527.       next input line is placed in the variable.
  528.  
  529.  
  530.    VER
  531.  
  532.       display my name and the version number.
  533.  
  534.  
  535.    SLEEP timeout
  536.  
  537.       Sleep for 'timeout' seconds.
  538.  
  539. *  PS
  540.  
  541. *    Gives the following info:
  542. *      
  543. *      Proc Command Name         CLI Type    Pri.  Address  Directory
  544. *       1   SHELL                Initial CLI   0      97b0  Stuff:shell
  545. *       2   sys:c/clockmem       Background  -10    2101a8  Workdisk:
  546. *       3   c:emacs              Background    0    212f58  Stuff:shell
  547. *       4   sys:c/VT100          Background    0    227328  Workdisk:
  548. *    
  549. *       Address is the addres of the task, directory is the process
  550. *       currently set directory.
  551.  
  552.  
  553. (H) SPECIAL SET VARIABLES
  554.  
  555. |   _prompt
  556. |        This variable is set to the command you wish executed that will
  557. |        create your prompt. Under manx version set this to the string
  558. |     for your prompt not a command to create the prompt. (Restriction
  559. |     due to commandline editing support.
  560.  
  561.    _history
  562.          This variable is set to a numerical value, and specifies how far
  563.          back your history should extend.
  564.  
  565.    _debug
  566.          Debug mode... use it if you dare.  must be set to some value
  567.  
  568.    _verbose
  569.          Verbose mode (for source files).  display commands as they are
  570.          executed.
  571.  
  572.    _maxerr
  573.          The worst (highest) return value to date.  To use this, you usually
  574.          set it to '0', then do some set of commands, then check it.  
  575.  
  576.    _lasterr
  577.          Return code of last command executed.  This includes internal
  578.          commands as well as external comands, so to use this variables
  579.          you must check it IMMEDIATELY after the command in question.
  580.  
  581.    _cwd
  582.          Holds a string representing the current directory we are in from
  583.          root.  The SHELL can get confused as to its current directory if
  584.          some external program changes the directory.  Use PWD to rebuild
  585.          the _cwd variable in these cases.
  586.  
  587.    _passed
  588.          This variable contains the passed arguments when you SOURCE a file
  589.          or execute a .sh file.  For instance:
  590.  
  591.          test a b c d
  592.  
  593.          -------- file test.sh ----------
  594.          echo $_passed
  595.          foreach i ( $_passed ) "echo YO $i"
  596.          --------------------------------
  597.  
  598.  
  599.    _path
  600.          This variable contains the search path when the shell is looking
  601.          for external commands.  The format is:  DIR,DIR,DIR  Each DIR must
  602.          have a trailing ':' or '/'.  The current directory is always
  603.          searched first.  The entire path will be searched first for the
  604.          <command>, then for <command>.sh (automatic shell script sourcing).
  605.  
  606.          The default _path is set to  "c:,df1:c/,df0:c/,ram:,ram:c/"
  607. *     When using 'run' command Shell will now use it's own search
  608. *     path first to find the command to run. If it fails to find
  609. *     the command (but the Run command was found) it executes the
  610. *     command line anyway to let amigaDos search path take over.
  611.  
  612. *  _insert
  613. *        Set's the default for insert/overtype mode for command line
  614. *     editing. ^A toggles between, but after <RET> the default is 
  615. *         set back as indicated by this variable. By default _insert is 1
  616. *        indicating insert mode on setting to zero will make overtype
  617. *     the default.
  618.  
  619. *  _width
  620. *     Indicates the console window width, 77 if unset. 
  621. *      Will change automatically if the user resizes the window.
  622.     
  623.  
  624. (I) EXAMPLE .login file.
  625.  
  626.    from a CLI or the startup-script say 'SHELL filename'.  That file
  627.    is sourced first.  thus, 'SHELL .login' will set up your favorite
  628.    aliases:
  629.  
  630. ------------------------------------------------------------------------
  631. .LOGIN
  632. ------------------------------------------------------------------------
  633.  
  634. # -Steve's .login file- #
  635.  
  636. echo -n    "Enter Date [DD-MMM-YY HH:MM] ";input new; DATE $new
  637.  
  638. # ------My search path ------- #
  639.  
  640. set   _path  ram:c/,ram:,c:,df0:c/,df1:c/,sys:system/,sys:utilities
  641.  
  642. # -------Function keys-------- #
  643.  
  644. set   f1     dir df0:
  645. set   f2     dir df1:
  646. set   F1     dir -s df0:
  647. set   F2     dir -s df1:
  648. set   f3     info
  649. set   f4     ps
  650.  
  651. # ---------Quickies---------- #
  652.  
  653. # -query delete- #
  654. #another favorite eg    qd *.c
  655. alias qd "%q foreach i ( $q ) \"echo -n Delete [n] ;input a;if $a = y;del $i;endif\""
  656.  
  657. alias delete rm
  658. alias rename mv
  659. alias makedir mkdir
  660. alias print "%q copy $q prt:"
  661. alias info  "devinfo df0: df1: ram:"
  662. alias tosys "assign c: SYS:c"
  663. alias toram "assign c: RAM:c;"
  664. alias tomanx "assign c: MANX:c; manxinit"
  665. alias d     "dir -se .info"
  666. alias clr   "echo -n ^l"
  667. alias wb    "loadwb"
  668. alias pref  "sys:preferences"
  669. alias cal   "run sys:utilities/calculator"
  670.  
  671. # ------Applications---------- #
  672.  
  673. alias em    "run emacs"
  674. alias vt    "run sys:c/VT100"
  675.  
  676. # --------Finish Up----------- #
  677.  
  678. ver ;echo -n "Shell loaded on ";date
  679.  
  680.  
  681. ------------------------------------------------------------------------
  682. MANXINIT.SH
  683. ------------------------------------------------------------------------
  684. SET INCLUDE=AC:include CCTEMP=ram:
  685. makedir ram:lib;Set CLIB=RAM:lib/;copy AC:lib/$libfile ram:lib"
  686. alias    cleanup    "del >NIL: ram:lib/* ram:lib"
  687.  
  688. #run make in background at lower priority:
  689. alias    make    "%q run ChangeTaskPri -5 +^J^J MAKE $q"
  690.  
  691.  
  692. ------------------------------------------------------------------------
  693. RAM.SH
  694. ------------------------------------------------------------------------
  695. cp c:run ram:; cp c:assign ram:; cp c:cp ram:; assign c: ram:
  696.  
  697.